package Day2025_03_16;

public class LeetCode376 {
    public int wiggleMaxLength(int[] nums) {
        int n = nums.length;
        int[] f = new int[n];
        int[] g = new int[n];
        for (int i = 0; i < n; i++) {
            f[i] = g[i] = 1;
        }
        int ret = 1;
        for (int i = 1; i < n; i++) {
            for (int j = i - 1; j >= 0; j--) {
                if (nums[i] - nums[j] > 0) f[i] = Math.max(f[i], g[j] + 1);
                if (nums[i] - nums[j] < 0) g[i] = Math.max(g[i], f[j] + 1);
            }
            ret = Math.max(f[i], ret);
            ret = Math.max(g[i], ret);
        }
        return ret;
    }
}
